package com.dark.base;

import com.dark.aop.sleuth.TraceUtil;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * ClassName: Result
 * Description:Result
 *
 * @author chengluchao
 * @date: 2022/8/13 3:47 PM
 * @since 1.4.8
 */
@ApiModel(description = "result")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private String requestId;
    private int code;
    private String message;
    private T data;



    public Result(T data) {
        this.data = data;
        this.code = FlowerFallingErrorCodeEnmu.SUCCESS.getCode();
        this.message = FlowerFallingErrorCodeEnmu.SUCCESS.getMessage();
    }

    public Result(FlowerFallingErrorCodeEnmu errorCodeEnmu) {
        this.code = errorCodeEnmu.getCode();
        this.message = errorCodeEnmu.getMessage();
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }
    public String getRequestId() {
        return requestId == null ? TraceUtil.getTraceId() : requestId;
    }
}
